cmake_minimum_required(VERSION 3.18)

project(BNSPlayer LANGUAGES CXX)

# 禁用 Qt 资源文件的 Zstd 压缩，解决嵌入式平台链接错误
set(QT_RCC_FLAGS "-no-zstd")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(QT_QML_GENERATE_QMLLS_INI ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(SOURCES
    src/FrameQueue.cpp
    src/AudioFilter.cpp
    src/AudioPlayer.cpp
    # src/AudioQueue.cpp
    src/Decoder.cpp
    src/FrameFilter.cpp
    src/FrameProvider.cpp
    src/PacketQueue.cpp
    src/VideoFrameFilter.cpp
    # src/VideoFrameQueue.cpp
    src/FrameProvider.h
    src/FrameQueue.h
    src/AudioFilter.h
    src/AudioPlayer.h
    # src/AudioQueue.h
    src/Decoder.h
    src/FrameFilter.h
    src/PacketQueue.h
    src/VideoFrameFilter.h
    # src/VideoFrameQueue.h
    src/SystemClockSynchronizer.h
    src/SystemClockSynchronizer.cpp
    src/ISynchronizer.h
    src/ISynchronizer.cpp
    src/MediaInspector.h
    src/MediaInspector.cpp
    src/FrameRenderer.h
    src/FrameRenderer.cpp
)

find_package(Qt6 COMPONENTS Gui Qml Quick Multimedia Widgets OpenGLWidgets Sql)

add_executable(BNSPlayer src/main.cpp ${SOURCES} BNSPlayer.qrc)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
set_target_properties(BNSPlayer PROPERTIES
    WIN32_EXECUTABLE TRUE
)

target_compile_definitions(BNSPlayer PRIVATE -D__STDC_CONSTANT_MACROS)

target_link_libraries(BNSPlayer PRIVATE
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Gui
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Quick
    Qt${QT_VERSION_MAJOR}::Qml
    Qt${QT_VERSION_MAJOR}::Multimedia
    Qt${QT_VERSION_MAJOR}::OpenGLWidgets
    Qt${QT_VERSION_MAJOR}::Sql
)


if(WIN32)
target_include_directories(BNSPlayer PRIVATE $ENV{FFMPEG}/include)
target_link_libraries(BNSPlayer PRIVATE $ENV{FFMPEG}/lib/avcodec.lib
    $ENV{FFMPEG}/lib/avdevice.lib
    $ENV{FFMPEG}/lib/avformat.lib
    $ENV{FFMPEG}/lib/avutil.lib
    $ENV{FFMPEG}/lib/swresample.lib
    $ENV{FFMPEG}/lib/swscale.lib
    $ENV{FFMPEG}/lib/avfilter.lib)
elseif(LINUX)

target_include_directories(BNSPlayer PRIVATE $ENV{FFMPEG}/include)
target_link_libraries(BNSPlayer PRIVATE libavcodec.so
    libavdevice.so
    libavformat.so
    libavutil.so
    libswresample.so
    libswscale.so
    libavfilter.so)    

    # 添加调试符号优化配置
    if(CMAKE_BUILD_TYPE STREQUAL "Debug")
        # 生成分离的调试符号
        set_target_properties(BNSPlayer PROPERTIES
            LINK_FLAGS "-Wl,--compress-debug-sections=zlib"
            CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g1 -fdebug-types-section"
        )
    endif()
endif()

